package com.cold.demo.rabbitmq.demo3;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;

/**
 * @author: zyc
 */
@SpringBootConfiguration
public class AMQConfig implements ApplicationContextAware, Lifecycle {

    private ApplicationContext applicationContext;

    @PostConstruct
    private void init(){
        RabbitTemplate rabbitTemplate = applicationContext.getBean(RabbitTemplate.class);
        
    }

    /*@Bean
    public Queue queue_test1(){
        return new Queue("test1",true,false,false,null);
    }*/

    public RabbitTemplate rabbitTemplate(){
        RabbitTemplate rabbitTemplate = new RabbitTemplate();
        return rabbitTemplate;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    @Override
    public void start() {
        System.out.println("start");
    }

    @Override
    public void stop() {
        System.out.println("stop");
    }

    @Override
    public boolean isRunning() {
        return true;
    }
}
